//
//  MineTypeTableViewCell.m
//  CarUser
//
//  Created by ayi on 2019/1/6.
//  Copyright © 2019 王森林. All rights reserved.
//

#import "MineTypeTableViewCell.h"

#import "UIButton+Util.h"
@interface MineTypeTableViewCell()

@property (nonatomic, strong) UIButton *Btn1;//
@property (nonatomic, strong) UIButton *Btn2;//
@property (nonatomic, strong) UIButton *Btn3;//
@property (nonatomic, strong) UIButton *Btn4;//

@end

@implementation MineTypeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

+ (MineTypeTableViewCell *)initWithSteDefaut:(UITableView *)tab andreuseIdentifier:(NSString *)reuseIdentifier{
    MineTypeTableViewCell *cell = [tab dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[MineTypeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _Btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        _Btn1.titleLabel.font = FONT_SIZE(13);
        [_Btn1 setTitle:@"订单" forState:UIControlStateNormal];
        [_Btn1 setTitleColor:Common_TextColor forState:UIControlStateNormal];
        [_Btn1 setImage:IMG(@"id_my_order") forState:UIControlStateNormal];
        [_Btn1 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        _Btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        _Btn2.titleLabel.font = FONT_SIZE(13);
        [_Btn2 setTitle:@"收藏夹" forState:UIControlStateNormal];
        [_Btn2 setTitleColor:Common_TextColor forState:UIControlStateNormal];
        [_Btn2 setImage:IMG(@"ic_my_favorite") forState:UIControlStateNormal];
        [_Btn2 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        _Btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        _Btn3.titleLabel.font = FONT_SIZE(13);
        [_Btn3 setTitle:@"预约" forState:UIControlStateNormal];
        [_Btn3 setTitleColor:Common_TextColor forState:UIControlStateNormal];
        [_Btn3 setImage:IMG(@"ic_my_subscribe") forState:UIControlStateNormal];
        [_Btn3 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        _Btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
        _Btn4.titleLabel.font = FONT_SIZE(13);
        [_Btn4 setTitle:@"车友圈" forState:UIControlStateNormal];
        [_Btn4 setTitleColor:Common_TextColor forState:UIControlStateNormal];
        [_Btn4 setImage:IMG(@"ic_my_moment") forState:UIControlStateNormal];
        [_Btn4 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        _btn1CountLab = [UILabel customInitLabWithFont:10 andTextColor:Common_TextColor2 andAlign:NSTextAlignmentCenter];
        _btn1CountLab.backgroundColor = Common_BG_yellow;
        _btn2CountLab = [UILabel customInitLabWithFont:10 andTextColor:Common_TextColor2 andAlign:NSTextAlignmentCenter];
        _btn2CountLab.backgroundColor = Common_BG_yellow;
        _btn3CountLab = [UILabel customInitLabWithFont:10 andTextColor:Common_TextColor2 andAlign:NSTextAlignmentCenter];
        _btn3CountLab.backgroundColor = Common_BG_yellow;
        _btn4CountLab = [UILabel customInitLabWithFont:10 andTextColor:Common_TextColor2 andAlign:NSTextAlignmentCenter];;
        _btn4CountLab.backgroundColor = Common_BG_yellow;
        
        [self.contentView addSubview:_Btn1];
        [self.contentView addSubview:_Btn2];
        [self.contentView addSubview:_Btn3];
        [self.contentView addSubview:_Btn4];
        [self.contentView addSubview:_btn1CountLab];
        [self.contentView addSubview:_btn2CountLab];
        [self.contentView addSubview:_btn3CountLab];
        [self.contentView addSubview:_btn4CountLab];
        
        [_Btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.left.and.bottom;
        }];
        
        [_Btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.bottom;
            make.left.equalTo(self.Btn1.mas_right);
            make.width.equalTo(self.Btn1.mas_width);
        }];
        
        [_Btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.bottom;
            make.left.equalTo(self.Btn2.mas_right);
            make.width.equalTo(self.Btn1.mas_width);
        }];
        
        [_Btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.right.and.bottom;
            make.left.equalTo(self.Btn3.mas_right);
            make.width.equalTo(self.Btn1.mas_width);
        }];
        
        CGFloat right = -([UIScreen mainScreen].bounds.size.width/4) * 0.19;
        CGFloat top = 96 * 0.18;
        //------------------lab
        [_btn1CountLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.Btn1.mas_centerX).offset(-right);
            make.top.equalTo(self.Btn1.mas_top).offset(top);
            make.height.mas_equalTo(12);
            make.width.mas_equalTo(12);
        }];
        //        [_willPayCountLab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        _btn1CountLab.layer.masksToBounds = YES;
        _btn1CountLab.layer.cornerRadius = 6;
        
        [_btn2CountLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.Btn2.mas_centerX).offset(-right);
            make.top.equalTo(self.Btn2.mas_top).offset(top);
            make.height.mas_equalTo(12);
            make.width.mas_equalTo(12);
        }];
        //         [_willSendCountLab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        _btn2CountLab.layer.masksToBounds = YES;
        _btn2CountLab.layer.cornerRadius = 6;
        
        [_btn3CountLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.Btn3.mas_centerX).offset(-right);
            make.top.equalTo(self.Btn3.mas_top).offset(top);
            make.height.mas_equalTo(12);
            make.width.mas_equalTo(12);
        }];
        //         [_willDeliveryCountLab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        _btn3CountLab.layer.masksToBounds = YES;
        _btn3CountLab.layer.cornerRadius = 6;
        
        [_btn4CountLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.Btn4.mas_centerX).offset(-right);
            make.top.equalTo(self.Btn4.mas_top).offset(top);
            make.height.mas_equalTo(12);
            make.width.mas_equalTo(12);
        }];
        //         [_completeCountLab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
        _btn4CountLab.layer.masksToBounds = YES;
        _btn4CountLab.layer.cornerRadius = 6;
        
        [_Btn1 btnTitleUnderImgWithHeight:-15];
        [_Btn2 btnTitleUnderImgWithHeight:-15];
        [_Btn3 btnTitleUnderImgWithHeight:-15];
        [_Btn4 btnTitleUnderImgWithHeight:-15];
    }
    return self;
}


- (void)btnAction:(UIButton *)btn{
    if (btn == self.Btn1) {
        [self selectorActionWithActionStatus:@(1)];
    }else if (btn == self.Btn2) {
        [self selectorActionWithActionStatus:@(2)];
    }else if (btn == self.Btn3) {
        [self selectorActionWithActionStatus:@(3)];
    }else if (btn == self.Btn4) {
        [self selectorActionWithActionStatus:@(4)];
    }
    
}

- (void)selectorActionWithActionStatus:(NSNumber *)status{
    UIViewController *vc = [self viewController];
    if ([vc respondsToSelector:NSSelectorFromString(@"pushToOrderListWithStauts:")]) {
        SEL functionSelector = NSSelectorFromString(@"pushToOrderListWithStauts:");
        NSMethodSignature *signature = [vc methodSignatureForSelector:functionSelector];
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
        [invocation setTarget:vc];
        [invocation setSelector:functionSelector];
        [invocation setArgument:&status atIndex:2];
        [invocation invoke];
    }
}

- (void)resetCountLabText:(NSString *)count andindex:(NSInteger )index{
    UILabel *onelab;
    switch (index) {
        case 0:
            onelab = self.btn1CountLab;
            break;
        case 1:
            onelab = self.btn2CountLab;
            break;
        case 2:
            onelab = self.btn3CountLab;
            break;
        case 3:
            onelab = self.btn4CountLab;
            break;
        default:
            break;
    }
    if (onelab != nil && onelab.superview != nil) {
        onelab.hidden = ![count integerValue];
        onelab.text = [NSString stringWithFormat:@"%@",count];
        CGSize size = [CommonMethod getWidthWithStr:onelab.text andFont:onelab.font andWidth:BOUNDWIDTH];
        size.width = (size.width + 4)<12?12:(size.width + 4);
        [onelab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(size.width);
        }];
    }
}


@end
